local baonve = fk.CreateSkill {
  name = "lingling__baonve",
}

Fk:loadTranslationTable{
  ["lingling__baonve"] = "暴虐",
  [":lingling__baonve"] = "准备阶段，你可以对一名体力少于你的角色随机造成0~2点伤害，若为2点，其随机对你造成0~2点伤害。",

  ["#lingling__baonve-choose"] = "暴虐：对一名体力值少于你的角色随机造成0~2点伤害！",
}

baonve:addEffect(fk.EventPhaseStart, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(baonve.name) and player.phase == Player.Start and
      table.find(player.room:getOtherPlayers(player, false), function(p)
        return p.hp < player.hp
      end)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room:getOtherPlayers(player, false), function(p)
      return p.hp < player.hp
    end)
    local to = room:askToChoosePlayers(player, {
      targets = targets,
      min_num = 1,
      max_num = 1,
      prompt = "#lingling__baonve-choose",
      skill_name = baonve.name,
      cancelable = true,
    })
    if #to > 0 then
      event:setCostData(self, {tos = to})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).tos[1]
    local n = math.random(0, 2)
    room:damage{
      from = player,
      to = to,
      damage = n,
      skillName = baonve.name,
    }
    if n == 2 and not player.dead and not to.dead then
      n = math.random(0, 2)
      room:damage{
        from = to,
        to = player,
        damage = n,
        skillName = baonve.name,
      }
    end
  end,
})

return baonve
